# -*- coding: utf-8 -*-
"""
Created on Sat May  2 23:15:00 2020

@author: RaingEye
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import time
#导入时间模块

import warnings
warnings.filterwarnings('ignore')
#不发出警告

from bokeh.plotting import figure, show, output_file
from bokeh.models import ColumnDataSource
#导入boekh绘图模块

'''
(1)创建数据
'''
data_norm = pd.DataFrame({'正态分布': np.random.normal(loc = 60, scale = 15, size = 10000)})
data_exp = pd.DataFrame({'指数分布': np.random.exponential(scale =15, size = 10000) + 45})

fig, axes =  plt.subplots(2, 1, figsize = (10, 4))
data_norm.hist(bins = 50)
data_exp.hist(bins = 50)


'''
(2)构建一个函数，生成样本数据
'''
def create_sample(n, gender):
    sample_data = pd.DataFrame({'fortune':np.random.exponential(scale = 15, size = n) + 45,
                                'apperance': np.random.normal(loc = 60, scale = 15, size = n),
                                'character': np.random.normal(loc = 60, scale = 15, size = n)},
                                index = [gender + str(i) for i in range(1, n+1)])
    sample_data.index.name = 'id'
    sample_data['score'] = sample_data.sum(axis = 1)/3
    return sample_data
    
sample_m = create_sample(10000, 'm')      #男性样本数据
sample_f = create_sample(10000, 'f')      #女性样本数据

fig, axes = plt.subplots(2, 1, figsize = (12, 8))
sample_m[['fortune', 'apperance', 'character']].iloc[:30].plot(kind = 'bar',
        colormap = 'Blues_r', stacked = True, grid = True, ax = axes[0])
sample_f[['fortune', 'apperance', 'character']].iloc[:30].plot(kind = 'bar',
        colormap = 'Reds_r', stacked = True, grid = True, ax = axes[1  ])
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
